<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>快吃管理系统</title>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/main.css"/>
    <script type="text/javascript" src="__PUBLIC__/js/libs/modernizr.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/jquery-3.2.1.min.js"></script>
    <script src="__PUBLIC__/js/layer/layer.js"></script>

</head>
<body style="margin:0px;padding:0px">
<style type="text/css" media="screen">
.total{
    width:100%;
    height: 100%;
    background-color: #B3B3B3;
    position: fixed;
    top:0px;
    opacity:0.5;
    margin:0px;
    z-index: 2;
    display:none;
}    
.add{
    width:500px;
    height:450px;
    background-color: #fff;
    position:fixed;
    top:50px;
    left:30%;
    border-radius: 5px;
z-index: 300;
display: none;
}
.add span
{
    float:right;
    font-size: 30px;
    margin-top: 10px;
    margin-right: 20px;
    color:#666;
    cursor: pointer;
}
.add span:hover
{
    color:#aaa;
}
.add p
{
    font-size: 18px;
    float:left;
    margin-top: 40px;
    margin-left:200px;
    color:#000;
    font-family: '微软雅黑';

}
.addtab
{
    float:left;
/*    margin-top:10px;*/
    margin-left: 90px;
}
.addtab tr
{
    float:left;
    margin-top: 20px;
    width:300px;
}
.addtab th
{
    width:90px;
    font-size: 15px;
    font-family: '微软雅黑';
    color:#000;
    float:left;
    font-weight:normal;
}
.addtab input
{
    border-radius: 5px;
    float:left;
}
.btn12
{
    width:160px;
    height:40px;
    letter-spacing: 10px;
    font-size: 16px;
  
}
.require-red {
    color: #f60;
    font-family: serif;
    margin-right: 3px;
}
</style>
<div class="total">
</div>
<div class="add" id="add">
<span onclick="ad()">×</span>
<p>新增管理员</p>
<form id="myform" enctype="multipart/form-data">
<table  class="addtab">
<tr><th><i class="require-red">*</i>用户名：</th><td><input name='username' type='text'  placeholder="用户名"></td></tr>
<tr><th><i class="require-red">*</i>密码：</th><td><input name='password' type='password'  placeholder="密码"></td></tr>
<tr><th><i class="require-red">*</i>姓名：</th><td><input name='name' type='text'  placeholder="姓名"></td></tr>
<tr><th><i class="require-red">*</i>性别：</th><td>
<select name="sex" style="width:187px;height:25px; border-color:#ccc; border-radius:5px">
    <option value="">请选择</option>
    <option value="1">男</option>
    <option value="2">女</option>
</select></td></tr>
<tr><th><i class="require-red">*</i>工号：</th><td><input name='teacher_id' type='text'  placeholder="工号"></td></tr>
<tr><th><i class="require-red">*</i>所属食堂：</th><td>
<select name="restaurant_id" style="width:187px;height:25px; border-color:#ccc; border-radius:5px">
    <option value="">请选择</option>
    {volist name='resdata' id='x'}
    <option value="{$x.restaurant_id}">{$x.restaurant_name}</option>
    {/volist}
</select></td></tr>
<tr><th></th><td><input class="btn btn-primary btn6 btn12 suba" name="sub" value="添加" type="button"></td></tr>
</table>
</form>

</div>
<p style="margin-top:15px;margin-left:40px; font-size:16px; border-left:3px #006dcc solid; padding-left:5px">查看所有管理员</p>
<div class="container clearfix">
    <div class="main-wrap">
        <div class="search-wrap">
            <div class="search-content">
            </div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="javascript:;" onclick="ad()"><i class="icon-font"></i>新增管理员</a>
                    </div>
                </div>
                <div class="result-content">
                    <table class="result-tab" width="100%" id="addto">
                        <tr>
                            <th>管理员ID</th>
                            <th>用户名</th>
                            <th>姓名</th>
                            <th>性别</th>
                            <th>工号</th>
                            <th>所属食堂</th>
                            <th>操作</th>
                        </tr>
                        {volist name="data" id="v"}
                        <tr>
                            <td>{$v.user_id}</td>
                            <td>{$v.username}</td>
                            <td>{$v.name}</td>
                            <td>{if condition="$v.sex eq '1'"}男
									{else /} 女
									{/if}</td>
                            <td>{$v.teacher_id}</td>
                            <td>{$v.restaurant_name}</td>
                            <td>
                            	<a class="link-del" href="{:url('UserType/update',['user_id'=>$v.user_id])}" >修改</a>
                       			<a class="link-del" href="javascript:;" onclick="dele('{$v.user_id}')">删除</a>
                            </td>
                            </tr>
                            {/volist}
                    </table>
                    <!-- <div class="list-page"> 2 条 1/1 页</div> -->
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    function ad()
    {
        $('.total').toggle(500);
        $('#add').toggle(1000);

    }



function dele(user_id){
        $.get("{:url('UserType/deletefun')}",{user_id:user_id}, function(data) {
            if(data.code=='1')
            {
                location.reload();        
            }
        else
           layer.msg(data.message, { offset: ['0px', '40%'], icon:5,time:2000});    
            
        });

    }

    $('.suba').click(function()
        {
        var username=$('input[name=username]');
        var password=$('input[name=password]');
        var name=$('input[name=name]');
        var sex=$('select[name=sex]');
        var teacher_id=$('inpput[name=teacher_id]');
 		var restaurant_id=$('select[name=restaurant_id]');


        if(username.val()=="")
        {
            layer.msg('用户名不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            username.focus();
            return ;
        }

        if(password.val()=="")
        {
            layer.msg('密码不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            password.focus();
            return ;
        }

        if(name.val()=="")
        {
            layer.msg('姓名不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            name.focus();
            return ;
        }

        if(sex.val()=="")
        {
            layer.msg('性别不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            sex.focus();
            return ;
        }

        if(teacher_id.val()=="")
        {
            layer.msg('工号不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            teacher_id.focus();
            return ;
        }

       if(restaurant_id.val()=="")
        {
            layer.msg('所属食堂不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            restaurant_id.focus();
            return ;
        }


        var formData = new FormData($("#myform")[0]);//获取表单数据        
          $.ajax({
               url: "{:url('UserType/addfun')}",//提交地址
               type: 'POST',
               data: formData,
               async: false,
               cache: false,
               contentType: false,
               processData: false,
               success: function (returndata) {
                if(returndata.code=='1'){
                  layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                    location.reload(); 
                  });
                }
                else
                layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});            
               },
               error: function (returndata) {
                layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});

           }
          });     

        });
</script>
</html>